home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d7 / litecom6.arc / QBTTL.C < prev    next >
Text File  |  1991-08-29  |  26KB  |  1,267 lines

  1. /*
  2. **  QBTTL is a complete, if somewhat limited, terminal emulation
  3. **  program  designed to demonstrate the use of the LiteComm(tm)
  4. **  ToolBox.  The executable version is included so that you can
  5. **  try it out while viewing the code.  To successfully create a
  6. **  new version of QBTTL, you must have the XMODEM and WXMODEM engines
  7. **  which are provided as part of your registration package.  The
  8. **  QUICKB functionality is derived from public domain code, and adapted
  9. **  by Information Technology for use with LiteComm.
  10. **  Also note that the windowing parts of the program are based upon
  11. **  CXL, a shareware product of Innovative Data Concepts.
  12. **  You must have this product and be a LiteComm registrant to successfully
  13. **  compile a new version of QBTTL.
  14. **
  15. **  While non-registered users cannot create a new version of QBTTL, as-is
  16. **  we have provided the source as part of the distribution package to
  17. **  help you in your understanding of the way in which the LiteComm
  18. **  Communications ToolBox can be used.
  19. **
  20. **  QBTTL functions as a vidtex terminal when used in conjuction with
  21. **  CompuServe.  In addition, it will run on any communications port from
  22. **  1 thru 4, defaulting to port 2 (COM2).  To execute QBTTL on other than
  23. **  COM2, specify
  24. **    QBTTL n
  25. **  where n is a number from 1 to 4.
  26. **
  27. **  Please note also that, to send a Ctrl-C, you must use the Alt-C keys
  28. **
  29. **  Information Technology, Ltd.
  30. */
  31.  
  32. #include "litecomm.h"
  33. #include "lcproto.h"
  34. #include "lcpxm.h"
  35. #include "lczm.h"
  36. #include "cxlkey.h"
  37. #include "cxlstr.h"
  38. #include "cxlwin.h"
  39.  
  40. #include <stdlib.h>
  41. #ifdef __TURBOC__
  42. #include <dir.h>
  43. #include <dos.h>
  44. #include <fcntl.h>
  45. #include <sys\stat.h>
  46. #include <io.h>
  47. #include <mem.h>
  48. #include <string.h>
  49. #endif
  50.  
  51. #ifdef M_I86
  52. #include <signal.h>
  53. #include <conio.h>
  54. #include <ctype.h>
  55. #include <dos.h>
  56. #include <fcntl.h>
  57. #include <stdio.h>
  58. #include <io.h>
  59. #include <string.h>
  60. #include <sys\types.h>
  61. #include <sys\stat.h>
  62.  
  63. #endif
  64.  
  65. #ifdef __TURBOC__
  66. unsigned _stklen = 16384;
  67. #endif
  68.  
  69. #define CTRLX 0x18
  70.  
  71. #define ESC 0x1b
  72. #define ENQ 0x05
  73.  
  74. int nocbrk();
  75. void selproto(void);
  76. void terminal(void);
  77. void chgcomm(void);
  78. void procesc(void);
  79. void moveleft(void);
  80. void moveright(void);
  81. void moveup(void);
  82. void movedn(void);
  83. void show_modem(unsigned char);
  84. void simtab();
  85. void setcursorpos(void);
  86. void send(void);
  87. void recv(void);
  88. void xupload(void);
  89. void xdnload(void);
  90. void wupload(void);
  91. void wdnload(void);
  92. void yzupload(void);
  93. void yzdnload(void);
  94. int kb_abort(void);
  95.  
  96. /*
  97. **  Comm parameters - human-readable form
  98. */
  99. int baud = 2400;
  100. char parity = 'N';
  101. int data = 8;
  102. int stop = 1;
  103.  
  104. /*
  105. **  Comm parameters - Litecomm form
  106. */
  107. unsigned pbaud = 2400;
  108. unsigned pparity = NPARITY;
  109. unsigned pbits = BIT8;
  110. unsigned pstop = STOP1;
  111. unsigned protocol = XMODEM;
  112. unsigned port = 1;
  113.  
  114. int xmode = 0;                          /* xmodem type */
  115. int yxmode = 0;                            /* use small blocks */
  116. int halfd = 0;                          /* half-duplex */
  117. int hostm = 0;                          /* host mode */
  118. int ctlc_hit = FALSE;
  119.  
  120. char MODEMSET0[] = "ATZ\r";
  121. char MODEMSET1[] = "ATT E0\r";
  122. char MODEMSET2[] = "ATC1 V0 X1 S0=1 M1\r";
  123.  
  124. /*
  125. ** protocol control block pointer - Rev 6 form
  126. */
  127. PROTO *p;
  128.  
  129. WINDOW mwin;                             /* for CXL */
  130. WINDOW swin;
  131.  
  132. int mbd;
  133. int mbg;
  134. int msay;
  135. int mact;
  136. int mnact;
  137. int mtitle;
  138. int sbd;
  139. int sbg;
  140. int ssay;
  141. int sact;
  142. int snact;
  143. int stitle;
  144. char    strbuf[80];                   /* for sprintf usage */
  145.  
  146. void main(argc, argv)
  147. int    argc;
  148. char *argv[];
  149. {
  150.     int    opt;
  151.  
  152. #ifdef M_I86
  153.     signal(SIGINT, nocbrk);               /* set Ctrl-Break handler */
  154. #endif
  155.  
  156. #ifdef __TURBOC__
  157.     ctrlbrk(nocbrk);
  158. #endif
  159.  
  160. /*
  161. **  check for a port parameter
  162. */
  163.     if (argc > 1)
  164.     {
  165.         port = atoi(argv[1]);
  166.         if ((port < 1) || (port > 4))
  167.         {
  168.             puts("Invalid Port Specified\n");
  169.             exit(4);
  170.         }
  171.     }
  172.  
  173. /*
  174. ** establish windowing environment
  175. */
  176.     if ((mwin=wopen(0,0,23,79,5,(WHITE | _BLACK), (WHITE | _BLACK))) == 0)
  177.         wperror("mwin:Not Enough Memory");
  178.     if ((swin=wopen(24,0,24,79,5,(BLACK | _LGREY), (BLACK | _LGREY))) == 0)
  179.         wperror("swin:Not Enough Memory");
  180.     wactiv(mwin);
  181.  
  182. /*
  183. ** set-up the comm port
  184. */
  185.     if (comm_opn(port,2400,NPARITY,BIT8,STOP1,2048,2048,FALSE) == -1)
  186.     {
  187.         wperror("Can't open port");
  188.         abort();
  189.     }
  190.  
  191. /*
  192. ** allocate the protocol control block
  193. */
  194.     if ((p = lcp_alloc(port)) == NULL)
  195.     {
  196.         wperror("Cant make proto control block");
  197.         abort();
  198.     }
  199.     lcp_abort = kb_abort;
  200.  
  201.     while (1)
  202.     {
  203.         wclear();
  204.         wputs("-- MAIN MENU --\n");
  205.         wputs("T - enter Terminal mode\n");
  206.         wputs("    Alt-X leaves terminal mode\n");
  207.         wprintf("H - toggle Host mode (now %s)\n",hostm ? "ON":"OFF");
  208.         wprintf("G - toGgle half-duplex mode (now %s)\n",halfd ? "ON":"OFF");
  209.         wprintf("C - change Comm parameters (now %d,%c,%d,%d)\n",
  210.                 baud,parity,data,stop);
  211.         wputs("P - Select protocol, currently ");
  212.         switch(protocol)
  213.         {
  214.             case XMODEM:
  215.                 wputs("XModem\n");
  216.                 break;
  217.             case XMODEM1K:
  218.                 wputs("1K XModem\n");
  219.                 break;
  220.             case WXMODEM:
  221.                 wputs("Windowed XModem\n");
  222.                 break;
  223.             case YMODEM:
  224.                 wputs("YModem\n");
  225.                 break;
  226.             case ZMODEM:
  227.                 wputs("ZModem\n");
  228.                 break;
  229.         }
  230.         wputs("S - Send a file\n");
  231.         wputs("R - Receive a file\n");
  232.         wputs("Q - Quit\n\n");
  233.  
  234.         opt = getchf("THGPSRCQ", 0);
  235.         opt = toupper(opt);
  236.  
  237.         switch (opt)
  238.         {
  239.             case 'T':   terminal();
  240.                         break;
  241.             case 'H':   if (hostm)
  242.                             hostm = 0;
  243.                         else
  244.                         {
  245.                             hostm = 1;
  246.                             halfd = 0;
  247.                         }
  248.                         break;
  249.             case 'G':   if (halfd)
  250.                             halfd = 0;
  251.                         else
  252.                         {
  253.                             halfd = 1;
  254.                             hostm = 0;
  255.                         }
  256.                         break;
  257.             case 'P':    selproto();
  258.                         break;
  259.             case 'S':   send();
  260.                         break;
  261.             case 'R':   recv();
  262.                         break;
  263.             case 'C':   chgcomm();
  264.                         break;
  265.         }
  266.         if (opt == 'Q')
  267.             break;                      /* shut down time */
  268.     }                                   /* while (1) */
  269.  
  270.     comm_close(port,FALSE);
  271.     wcloseall();
  272.     lcp_free(p);                        /* release proto control */
  273.  
  274.     exit(0);
  275. }                                       /* main */
  276.  
  277. int nocbrk()
  278. {
  279. #ifdef M_I86
  280.     signal(SIGINT, SIG_IGN);             /* set Ctrl-Break handler */
  281. #endif
  282.     ctlc_hit = TRUE;
  283. #ifdef M_I86
  284.     signal(SIGINT, nocbrk);             /* set Ctrl-Break handler */
  285. #endif
  286.     return(TRUE);
  287. }
  288.  
  289. void terminal()
  290. {
  291.     int ch;
  292.     int row, col;
  293.  
  294.     wclear();
  295.  
  296.     while (1)
  297.     {
  298.         if ((ch = lc_get(port)) != -1)
  299.             switch (ch & 0x7f)
  300.             {
  301.                 case DLE:
  302.                     bp_DLE();
  303.                     wopen(6,25,10,50,1,(WHITE|_BLACK),(WHITE|_BLACK));
  304.                     wtitle("CIS RECEIVE FILE", TCENTER, (BLACK|_LGREY));
  305.                     wclose();
  306.                     break;
  307.                 case ENQ:
  308.                     bp_ENQ();
  309.                     break;
  310.                 case ESC:
  311.                     procesc();
  312.                     break;
  313.                 default:
  314.                     if (pparity != NPARITY)
  315.                         ch &= 0x7f;                /* strip parity */
  316.                     wputc(ch);
  317.                     if (hostm)
  318.                     {
  319.                         lc_put(port,ch);            /* echo back */
  320.                         if (ch == '\n')             /* was it return */
  321.                         {
  322.                             lc_put(port,'\n');      /* echo lf as well */
  323.                             wputc('\n');
  324.                         }
  325.                     }
  326.             }
  327.         show_modem (lc_mstat(port));
  328.  
  329.         if (kbmhit())                       /* anything typed ? */
  330.         {
  331.             ch = getxch();                  /* get input */
  332.             if (ch == 0x2d00)                /* ALT-X */
  333.                 return;
  334.             if (ch == 0x2e00)                /* ALT-X */
  335.                 ch = 0x2e03;
  336.             lc_put(port,ch & 0x007f);       /* xmit the char */
  337.             if (hostm || halfd)             /* local echo needed ? */
  338.             {
  339.                 wputc(ch);
  340.                 if (ch == '\n')             /* was it CR */
  341.                 {
  342.                     wputc('\n');     /* add LF */
  343.                     if (hostm)
  344.                         lc_put(port, '\n'); /* and send LF in host mode */
  345.                 }
  346.             }
  347.         }
  348.     }                                       /* while */
  349. }
  350.  
  351. void procesc()
  352. {
  353.     int ch;
  354.  
  355.  
  356.     ch = lc_getw(port);                    /* wait for actual command */
  357.  
  358.     switch (ch & 0x7f)
  359.     {
  360.         case 'A':
  361.             moveup();
  362.             break;
  363.         case 'B':
  364.             movedn();
  365.             break;
  366.         case 'C':
  367.             moveright();
  368.             break;
  369.         case 'D':
  370.             moveleft();
  371.             break;
  372.         case 'H':
  373.             wgotoxy(0,0);
  374.             break;
  375.         case 'I':
  376.             bp_ESC_I();
  377.             break;
  378.         case 'J':
  379.             wclreos();
  380.             break;
  381.         case 'K':
  382.             wclreol();
  383.             break;
  384.         case 'j':
  385.             wclear();
  386.             break;
  387.         case 'Y':
  388.             setcursorpos();
  389.             break;
  390.     }
  391. }                                        /* procesc */
  392.  
  393. void selproto()
  394. {
  395.     int opt;
  396.  
  397.     wclear();
  398.     wputs("-- SELECT PROTOCOL --\n");
  399.     wputs("1 - XMODEM\n");
  400.     wputs("2 - 1K XMODEM\n");
  401.     wputs("3 - Windowed XMODEM\n");
  402.     wputs("4 - YMODEM\n");
  403.     wputs("5 - ZMODEM\n");
  404.  
  405.     opt = getchf("12345", 0);
  406.     switch (opt)
  407.     {
  408.         case '1':
  409.             protocol = XMODEM;
  410.             break;
  411.         case '2':
  412.             protocol = XMODEM1K;
  413.             break;
  414.         case '3':
  415.             protocol = WXMODEM;
  416.             break;
  417.         case '4':
  418.             protocol = YMODEM;
  419.             break;
  420.         case '5':
  421.             protocol = ZMODEM;
  422.             break;
  423.     }
  424. }
  425.  
  426. void show_modem(unsigned char mdmstat)
  427. {
  428.     if ((mdmstat & 0x0f))            /* any status change ? */
  429.     {
  430.         wwprints(swin, 0, 2, (BLACK|_LGREY), "                      ");
  431.         if (mdmstat & CTS)
  432.             wwprints(swin, 0, 2, (BLACK|_LGREY), "CTS");
  433.         if (mdmstat & DSR)
  434.             wwprints(swin, 0, 8, (BLACK|_LGREY), "DSR");
  435.         if (mdmstat & DCD)
  436.             wwprints(swin, 0, 14, (BLACK|_LGREY), "DCD");
  437.         if (mdmstat & RI)
  438.             wwprints(swin, 0, 20, (BLACK|_LGREY), "RI");
  439.     }
  440. }                                       /* show_modem */
  441.  
  442. void setcursorpos()
  443. {
  444.     int    ch;
  445.     int    x;
  446.     int    y;
  447.  
  448.     while((ch = lc_get(port)) == -1)
  449.     ;
  450.     y = (ch & 0x7f) - 32;
  451.  
  452.     while((ch = lc_get(port)) == -1)
  453.     ;
  454.     x = (ch & 0x7f) - 32;
  455.     wgotoxy(y, x);
  456. }
  457.  
  458. struct text_info
  459. {
  460.     int   wintop,
  461.             winbottom,
  462.             winleft,
  463.             winright,
  464.             curx,
  465.             cury;
  466. };
  467.  
  468. void gettextinfo(r)
  469. struct text_info *r;
  470. {
  471.     struct _wrec_t  *tmp;    /* pointer to active window         */
  472.  
  473.     tmp = _winfo.active;
  474.     r->wintop = tmp->srow;
  475.     r->winleft = tmp->scol;
  476.     r->winbottom = tmp->erow;
  477.     r->winright = tmp->ecol;
  478.     wreadcur(&(r->cury), &(r->curx));
  479. }
  480.  
  481. void moveleft()
  482. {
  483.     int scurx,
  484.         scury;
  485.     struct text_info r;
  486.  
  487.     gettextinfo(&r);
  488.     scurx = r.curx;
  489.     scury = r.cury;
  490.  
  491.     scurx--;                             /* decrement x position */
  492.     if (scurx < r.winleft)
  493.     {
  494.         scury--;
  495.         scurx = r.winright;
  496.         if (scury < r.wintop);
  497.             scury = r.winbottom;
  498.     }
  499.     wgotoxy(scury, scurx);
  500. }                                        /* moveleft */
  501.  
  502. void moveright()
  503. {
  504.     int scurx,
  505.         scury;
  506.     struct text_info r;
  507.  
  508.     gettextinfo(&r);
  509.     scurx = r.curx;
  510.     scury = r.cury;
  511.  
  512.     scurx++;                             /* decrement x position */
  513.     if (scurx > r.winright)
  514.     {
  515.         scury++;
  516.         scurx = r.winleft;
  517.         if (scury > r.winbottom);
  518.             scury = r.wintop;
  519.     }
  520.     wgotoxy(scury, scurx);
  521. }                                        /* moveright */
  522.  
  523. void moveup()
  524. {
  525.     int scury;
  526.  
  527.     struct text_info r;
  528.  
  529.     gettextinfo(&r);
  530.     scury = r.cury;
  531.  
  532.     scury = r.cury - 1;
  533.     if (scury < r.wintop)
  534.         scury = r.winbottom;
  535.     wgotoxy(scury, r.curx);
  536. }                                        /* moveup */
  537.  
  538. void movedn()
  539. {
  540.     int scury;
  541.  
  542.     struct text_info r;
  543.  
  544.     gettextinfo(&r);
  545.     scury = r.cury;
  546.  
  547.     scury = r.cury + 1;
  548.     if (scury > r.winbottom)
  549.         scury = r.wintop;
  550.     wgotoxy(scury, r.curx);
  551. }
  552.  
  553. void simtab()
  554. {
  555.     int scurx,
  556.         scury;
  557.     struct text_info r;
  558.  
  559.     gettextinfo(&r);
  560.     scurx = r.curx;
  561.     scury = r.cury;
  562.  
  563.     do
  564.         scurx++;                         /* bump x position */
  565.     while (scurx % 9);
  566.  
  567.     if (scurx > r.winright)
  568.     {
  569.         scury++;
  570.         scurx = r.winleft;
  571.         if (scury > r.winbottom);
  572.         {
  573.             wgotoxy(r.winbottom, r.winright);
  574.             wputc('\n');
  575.             return;
  576.         }
  577.     }
  578.     wgotoxy(scury, scurx);
  579. }                                        /* simtab */
  580.  
  581.  
  582. void chgcomm()
  583. {
  584.     int opt;
  585.     unsigned sbaud;
  586.     unsigned sparity;
  587.     unsigned sbits;
  588.     unsigned sstop;
  589.     int hbaud;
  590.     char hparity;
  591.     int hdata;
  592.     int hstop;
  593.  
  594. /*
  595. ** get current default settings
  596. */
  597.     sbaud = pbaud;
  598.     sparity = pparity;
  599.     sbits = pbits;
  600.     sstop = pstop;
  601.     hbaud = baud;
  602.     hparity = parity;
  603.     hdata = data;
  604.     hstop = stop;
  605.  
  606.  
  607.     while (1)
  608.     {
  609.         wclear();
  610.         wputs("-- COMM PARAMETERS --\n");
  611.         wprintf("  (Presently %d,%c,%d,%d)\n",
  612.                 hbaud,hparity,hdata,hstop);
  613.         wputs("B - change Baud Rate\n");
  614.         wputs("P - change Parity\n");
  615.         wputs("D - change Data bits\n");
  616.         wputs("S - change Stop bits\n\n");
  617.         wputs("A - Abandon Changes\n");
  618.         wputs("Q - Quit to Main Menu\n\n");
  619.  
  620.         opt = getxch() & 0x007f;
  621.         opt = toupper(opt);
  622.  
  623.         switch (opt)
  624.         {
  625.             case 'A':
  626.                 return;
  627.             case 'Q':
  628.                 pbaud = sbaud;          /* reset the globals */
  629.                 pparity = sparity;
  630.                 pbits = sbits;
  631.                 pstop = sstop;
  632.                 baud = hbaud;
  633.                 parity = hparity;
  634.                 data = hdata;
  635.                 stop = hstop;
  636.                 comm_setup(port,pbaud,pparity,pbits,pstop);
  637.                 return;
  638.             case 'B':
  639.                 wputs("1 - 110, 2 - 300, 3 - 600, 4 - 1200, 5 - 2400\n");
  640.                 wputs("6 - 4800, 7 - 9600, 8 - 19200\n");
  641.                 opt = getxch() & 0x007f;
  642.                 switch (opt)
  643.                 {
  644.                     case '1': hbaud = 110;
  645.                               sbaud = 110;
  646.                               break;
  647.                     case '2': hbaud = 300;
  648.                               sbaud = 300;
  649.                               break;
  650.                     case '3': hbaud = 600;
  651.                               sbaud = 600;
  652.                               break;
  653.                     case '4': hbaud = 1200;
  654.                               sbaud = 1200;
  655.                               break;
  656.                     case '5': hbaud = 2400;
  657.                               sbaud = 2400;
  658.                               break;
  659.                     case '6': hbaud = 4800;
  660.                               sbaud = 4800;
  661.                               break;
  662.                     case '7': hbaud = 9600;
  663.                               sbaud = 9600;
  664.                               break;
  665.                     case '8': hbaud = 19200;
  666.                               sbaud = 19200;
  667.                               break;
  668.                     case '9': hbaud = 38400;
  669.                               sbaud = 38400;
  670.                               break;
  671.                 }
  672.                 break;
  673.             case 'P':
  674.                 wputs("1 - NONE, 2 - EVEN, 3 - ODD, 4 - MARK, 5 - SPACE\n");
  675.                 opt = getxch() & 0x007f;
  676.                 switch (opt)
  677.                 {
  678.                     case '1': hparity = 'N';
  679.                               sparity = NPARITY;
  680.                               break;
  681.                     case '2': hparity = 'E';
  682.                               sparity = EPARITY;
  683.                               break;
  684.                     case '3': hparity = 'O';
  685.                               sparity = OPARITY;
  686.                               break;
  687.                     case '4': hparity = 'M';
  688.                               sparity = MPARITY;
  689.                               break;
  690.                     case '5': hparity = 'S';
  691.                               sparity = SPARITY;
  692.                               break;
  693.                 }
  694.                 break;
  695.             case 'D':
  696.                 wputs("Number of Data Bits (5, 6, 7, 8)\n");
  697.                 opt = getxch() & 0x007f;
  698.                 switch (opt)
  699.                 {
  700.                     case '5': hdata = 5;
  701.                               sbits = BIT5;
  702.                               break;
  703.                     case '6': hdata = 6;
  704.                               sbits = BIT6;
  705.                               break;
  706.                     case '7': hdata = 7;
  707.                               sbits = BIT7;
  708.                               break;
  709.                     case '8': hdata = 8;
  710.                               sbits = BIT8;
  711.                               break;
  712.                 }
  713.                 break;
  714.             case 'S':
  715.                 wputs("Number of Stop Bits (1, 2)\n");
  716.                 opt = getxch() & 0x007f;
  717.                 switch (opt)
  718.                 {
  719.                     case '1': hstop = 1;
  720.                               sstop = STOP1;
  721.                               break;
  722.                     case '2': hstop = 2;
  723.                               sstop = STOP2;
  724.                               break;
  725.                 }
  726.                 break;
  727.         }
  728.     }
  729. }
  730.  
  731.  
  732. void send()
  733. {
  734.     wopen(6,25,10,50,1,(WHITE|_BLACK),(WHITE|_BLACK));
  735.     wtitle("SEND A FILE", TCENTER, (BLACK|_LGREY));
  736.  
  737.     lcp_setproto(p, protocol, TRUE);
  738.     switch (protocol)
  739.     {
  740.         case XMODEM:
  741.         case XMODEM1K:
  742.             xupload();
  743.             break;
  744.         case WXMODEM:
  745.             wupload();
  746.             break;
  747.         case YMODEM:
  748.         case ZMODEM:
  749.             yzupload();
  750.             break;
  751.     }
  752.  
  753.     wclose();
  754. }
  755.  
  756. void recv()
  757. {
  758.     wopen(6,25,10,50,1,(WHITE|_BLACK),(WHITE|_BLACK));
  759.     wtitle("RECEIVE A FILE", TCENTER, (BLACK|_LGREY));
  760.  
  761.     lcp_setproto(p, protocol, TRUE);
  762.     switch (protocol)
  763.     {
  764.         case XMODEM:
  765.         case XMODEM1K:
  766.             xdnload();
  767.             break;
  768.         case WXMODEM:
  769.             wdnload();
  770.             break;
  771.         case YMODEM:
  772.         case ZMODEM:
  773.             yzdnload();
  774.             break;
  775.     }
  776.  
  777.     wclose();
  778. }
  779.  
  780. void getfname(fname)
  781. char *fname;
  782. {
  783.     wclear();
  784.     wputs("File Name: ");
  785.     wgetns(fname, 13);
  786.     cputs("\n");
  787. }
  788.  
  789. void getpname(fname)
  790. char *fname;
  791. {
  792.     wclear();
  793.     wputs("Storage Path: ");
  794.     wgetns(fname, 13);
  795.     cputs("\n");
  796. }
  797.  
  798. void xupload(void)
  799. {
  800.     char fname[81];
  801.     int  fd;
  802.     unsigned char *bpos;
  803.     int toread;
  804.     int tosend;
  805.     unsigned char hdshk;
  806.     int hmode;
  807.     int result;
  808.  
  809.     getfname(fname);
  810.  
  811.     ctlc_hit = FALSE;
  812.     if (ctlc_hit == TRUE)
  813.     {
  814.         ctlc_hit = FALSE;
  815.         return;
  816.     }
  817.  
  818.     if (strblank(fname))
  819.         return;
  820.     strbtrim(fname);
  821.  
  822.     if ((fd = open(fname, (O_RDONLY|O_BINARY))) == -1)
  823.     {
  824.         wperror("Unable to open the file");
  825.         return;
  826.     }
  827. /*
  828. ** the file has been opened successfully...now switch the
  829. ** comport mode to 8 bits for xmodem protocol
  830. */
  831.     if (comm_setup(port,pbaud,NPARITY,BIT8,pstop) == ERR)
  832.     {
  833.         wperror("Unable to switch line mode");
  834.         return;
  835.     }
  836. /*
  837. ** begin file transmission to receiver -
  838. ** in receiver's specified mode
  839. */
  840.     if(protocol == XMODEM1K)
  841.         toread = 1024;
  842.     else
  843.         toread = 128;
  844.  
  845.     while (TRUE)
  846.     {
  847.         memset(p->buff, 0x1a, 1024);     /* clear buff, short rec */
  848.         if ((tosend = read(fd, p->buff, 1024)) < 1)  /* EOF or Error */
  849.         {
  850.             lcxteot(p);            /* send end of file */
  851.             wperror("End of Transmission");
  852.             break;
  853.         }
  854.         bpos = p->buff;
  855.         while (TRUE)
  856.         {
  857.             if (tosend <= 0)
  858.                 break;                        /* block sent completely */
  859.             if (protocol == XMODEM1K)
  860.                 if (tosend != toread)    /* short block */
  861.                 {
  862.                     toread = 128;       /* sending short */
  863.                     p->protocol = XMODEM;
  864.                 }
  865.             result = lcpxmsnd(p);
  866.             switch(result)           /* what action to take ? */
  867.             {
  868.                 case SUCCESS:
  869.                     wgotoxy(1,1);
  870.                     wclreol();
  871.                     wprintf("Sent record: %d",(p->rec-1));
  872.                     tosend -= toread;
  873.                     bpos += toread;
  874.                     break;
  875.                 case CAN:
  876.                     wperror("Cancel Received");
  877.                     break;
  878.                 case RETRIES:
  879.                     sprintf(strbuf, "Too Many tries...Rec %d",(p->rec-1));
  880.                     wperror(strbuf);
  881.                     break;
  882.                 default:
  883.                     wperror("Fatal transmission error");
  884.                     break;
  885.             }
  886.             if (result != SUCCESS)
  887.                 break;
  888.         }                                    /* inner while */
  889.         if (result != SUCCESS)
  890.             break;
  891.     }                                          /* while TRUE */
  892.     comm_setup(port,pbaud,pparity,pbits,pstop);
  893.     close(fd);                                 /* close down the file */
  894. }
  895.  
  896. void xdnload(void)
  897. {
  898.     char fname[81];
  899.     int  fd;
  900.     int result;
  901.  
  902.     ctlc_hit = FALSE;
  903.  
  904.     getfname(fname);
  905.     if (ctlc_hit == TRUE)
  906.     {
  907.         ctlc_hit = FALSE;
  908.         return;
  909.     }
  910.     if (strblank(fname))
  911.         return;
  912.     strbtrim(fname);
  913.  
  914.     if ((fd = open(fname,
  915.          (O_WRONLY|O_CREAT|O_TRUNC|O_BINARY),(S_IREAD|S_IWRITE))) == -1)
  916.     {
  917.         wperror("Unable to open the file");
  918.         return;
  919.     }
  920. /*
  921. ** the file has been opened successfully...now switch the
  922. ** comport mode to 8 bits for xmodem protocol
  923. */
  924.     if (comm_setup(port,pbaud,NPARITY,BIT8,pstop) == ERR)
  925.     {
  926.         wperror("Unable to switch line mode");
  927.         return;
  928.     }
  929. /*
  930. ** setup conditions for XMODEM receive
  931. */
  932.     while (TRUE)
  933.     {
  934.         while ((result = lcpxmrec(p)) == SUCCESS)
  935.         {
  936.             write(fd, p->buff, p->rbsize);  /* dump the block */
  937.             wgotoxy(1,1);
  938.             wclreol();
  939.             wprintf("Received record: %d",(p->rec-1));
  940.         }
  941.         switch(result)           /* unusual conditions */
  942.         {
  943.             case DUPSEQ:
  944.                 wgotoxy(1,1);
  945.                 wclreol();
  946.                 wputs("Duplicate record seq");
  947.                 break;
  948.             case CAN:
  949.                 wperror("Cancelled by host");
  950.                 break;
  951.             case EOT:
  952.                 wperror("Normal Termination");
  953.                 break;
  954.             case TOUT:
  955.                 wperror("SOH timeout");
  956.                 break;
  957.             case RETRIES:
  958.                 sprintf(strbuf, "Too Many tries...Rec %d",(p->rec-1));
  959.                 wperror(strbuf);
  960.                 break;
  961.             default:
  962.                 wperror("Fatal transmission error");
  963.                 break;
  964.         }
  965.         if ((result != SUCCESS) && (result != DUPSEQ))
  966.             break;
  967.     }                                          /* while TRUE */
  968.  
  969.     comm_setup(port,pbaud,pparity,pbits,pstop);
  970.     close(fd);                                 /* close down the file */
  971. }
  972.  
  973. void wupload(void)
  974. {
  975.     char fname[81];
  976.     int  fd;
  977.     int hmode;
  978.     int result;
  979.     int nrec;                           /* returned record */
  980.  
  981.     ctlc_hit = FALSE;
  982.     getfname(fname);
  983.     if (ctlc_hit == TRUE)
  984.     {
  985.         ctlc_hit = FALSE;
  986.         return;
  987.     }
  988.     if (strblank(fname))
  989.         return;
  990.     strbtrim(fname);
  991.  
  992.     if ((fd = open(fname,(O_RDONLY|O_BINARY))) == -1)
  993.     {
  994.         wperror("Unable to open the file");
  995.         return;
  996.     }
  997. /*
  998. ** the file has been opened successfully...now switch the
  999. ** comport mode to 8 bits for xmodem protocol
  1000. */
  1001.     if (comm_setup(port,pbaud,NPARITY,BIT8,pstop) == ERR)
  1002.     {
  1003.         wperror("Unable to switch line mode");
  1004.         return;
  1005.     }
  1006.     lc_xoff(port,TRUE);                    /* turn on auto xon-xoff */
  1007.  
  1008. /*
  1009. ** begin file transmission to receiver -
  1010. ** in receiver's specified mode
  1011. */
  1012.     while (TRUE)
  1013.     {
  1014.         memset(p->buff, 0x1a, 128);     /* clear buff, short rec */
  1015.         if (read(fd, p->buff, 128) < 1)  /* EOF or Error */
  1016.             nrec = -1;              /* defines End of File */
  1017.         else
  1018.             nrec = 0;
  1019.  
  1020.         result = lcpwxsnd(p, &nrec);
  1021.  
  1022.         switch(result)           /* what action to take ? */
  1023.         {
  1024.             case SUCCESS:
  1025.                 if (nrec == -1)  /* EOF confirmed */
  1026.                     wperror("End of Transmission");
  1027.                 else
  1028.                 {
  1029.                     wgotoxy(1,1);
  1030.                     wclreol();
  1031.                     wprintf("Sent record: %d",p->rec);
  1032.                 }
  1033.                 break;
  1034.             case CAN:
  1035.                 wperror("Cancel Received");
  1036.                 break;
  1037.             case RETRIES:
  1038.                 sprintf(strbuf, "Too Many tries...Rec %d",p->rec);
  1039.                 wperror(strbuf);
  1040.                 break;
  1041.             case RESEND:                /* must reset file position */
  1042.                 lseek(fd, (long)(nrec * 128), SEEK_SET);
  1043.                 break;
  1044.             default:
  1045.                 wperror("Fatal transmission error");
  1046.                 break;
  1047.         }
  1048.         if (result == RESEND)
  1049.             continue;
  1050.         if (result == SUCCESS)
  1051.             if (nrec == -1)             /* was EOF signalled */
  1052.                 break;
  1053.             else
  1054.                 continue;
  1055.         break;                          /* some other error */
  1056.     }                                          /* while TRUE */
  1057.     lc_xoff(port, FALSE);                         /* turn off auto xon/xoff */
  1058.     comm_setup(port,pbaud,pparity,pbits,pstop);
  1059.     close(fd);                                 /* close down the file */
  1060. }
  1061.  
  1062. void wdnload(void)
  1063. {
  1064.     char fname[81];
  1065.     int  fd;
  1066.     int result;
  1067.  
  1068.     ctlc_hit = FALSE;
  1069.  
  1070.     getfname(fname);
  1071.     if (ctlc_hit == TRUE)
  1072.     {
  1073.         ctlc_hit = FALSE;
  1074.         return;
  1075.     }
  1076.     if (strblank(fname))
  1077.         return;
  1078.     strbtrim(fname);
  1079.  
  1080.     if ((fd = open(fname,
  1081.          (O_WRONLY|O_CREAT|O_TRUNC|O_BINARY),(S_IREAD|S_IWRITE))) == -1)
  1082.     {
  1083.         wperror("Unable to open the file");
  1084.         return;
  1085.     }
  1086. /*
  1087. ** the file has been opened successfully...now switch the
  1088. ** comport mode to 8 bits for xmodem protocol
  1089. */
  1090.     if (comm_setup(port,pbaud,NPARITY,BIT8,pstop) == ERR)
  1091.     {
  1092.         wperror("Unable to switch line mode");
  1093.         return;
  1094.     }
  1095. /*
  1096. ** setup conditions for WXMODEM receive
  1097. */
  1098.     while (TRUE)
  1099.         {
  1100.         while ((result = lcpwxrec(p)) == SUCCESS)
  1101.         {
  1102.             write(fd, p->buff, 128);  /* dump the block */
  1103.             wgotoxy(1,1);
  1104.             wclreol();
  1105.             wprintf("Received record: %d", p->rec-1);
  1106.         }
  1107.         switch(result)           /* unusual conditions */
  1108.         {
  1109.             case DUPSEQ:
  1110.                 wgotoxy(1,1);
  1111.                 wclreol();
  1112.                 wputs("Duplicate record seq");
  1113.                 break;
  1114.             case CAN:
  1115.                 wperror("Cancelled by host");
  1116.                 break;
  1117.             case EOT:
  1118.                 wperror("Normal Termination");
  1119.                 break;
  1120.             case TOUT:
  1121.                 wperror("SOH timeout");
  1122.                 break;
  1123.             case RETRIES:
  1124.                 sprintf(strbuf, "Too Many tries...Rec %d",(p->rec-1));
  1125.                 wperror(strbuf);
  1126.                 break;
  1127.             default:
  1128.                 wperror("Fatal transmission error");
  1129.                 break;
  1130.         }
  1131.         if ((result != SUCCESS) && (result != DUPSEQ))
  1132.             break;
  1133.     }                                          /* while TRUE */
  1134.  
  1135.     comm_setup(port,pbaud,pparity,pbits,pstop); 
  1136.     close(fd);                                 /* close down the file */
  1137. }
  1138.  
  1139. void yzupload(void)
  1140. {
  1141.     char fname[81];
  1142.     int result;
  1143.     int i;
  1144.     int    j;
  1145.     int nrec;                           /* returned record */
  1146.     unsigned char *filelist[33];
  1147. #ifdef __TURBOC__
  1148.     struct ffblk fi;
  1149. #else
  1150.     struct find_t fi;
  1151. #endif
  1152.  
  1153.     ctlc_hit = FALSE;
  1154.     getfname(fname);
  1155.     if (ctlc_hit == TRUE)
  1156.     {
  1157.         ctlc_hit = FALSE;
  1158.         return;
  1159.     }
  1160.     if (strblank(fname))
  1161.         return;
  1162.     strbtrim(fname);
  1163.  
  1164.     i = 0;
  1165. #ifdef __TURBOC__
  1166.     result = findfirst(fname, &fi,0);
  1167.     while ((result != -1) && (i < 32))
  1168. #else
  1169.     result = _dos_findfirst(fname, 0, &fi);
  1170.     while ((result == 0) && (i < 32))
  1171. #endif
  1172.     {
  1173. #ifdef __TURBOC__
  1174.         filelist[i] = strdup(fi.ff_name);
  1175. #else
  1176.         filelist[i] = strdup(fi.name);
  1177. #endif
  1178.         if (filelist[i] == NULL)
  1179.         {
  1180.             for (j = 0; j < i; j++)
  1181.                 free(filelist[j]);
  1182.             return;
  1183.         }
  1184.         i++;
  1185. #ifdef __TURBOC__
  1186.         result = findnext(&fi);
  1187. #else
  1188.         result = _dos_findnext(&fi);
  1189. #endif
  1190.     }
  1191.     filelist[i] = strdup("");                    /* null name terminates list */
  1192.  
  1193. /* now switch the
  1194. ** comport mode to 8 bits for xmodem protocol
  1195. */
  1196.     if (comm_setup(port,pbaud,NPARITY,BIT8,pstop) == ERR)
  1197.     {
  1198.         wperror("Unable to switch line mode");
  1199.         for (j = 0; j < i; j++)
  1200.             free(filelist[j]);
  1201.         return;
  1202.     }
  1203.  
  1204. /*
  1205. ** begin file transmission to receiver -
  1206. ** in receiver's specified mode
  1207. */
  1208.     if (protocol == YMODEM)
  1209.         lcym_send(p, (unsigned char**) filelist);                /* go do it */
  1210.     else
  1211.         lczm_send(p, (long) pbaud, (unsigned char **) filelist);
  1212.  
  1213.     comm_setup(port,pbaud,pparity,pbits,pstop);    /* reset params */
  1214.     for (j = 0; j < i; j++)
  1215.         free(filelist[j]);
  1216. }
  1217.  
  1218. void yzdnload(void)
  1219. {
  1220.     char fname[81];
  1221.     int result;
  1222.  
  1223.     ctlc_hit = FALSE;
  1224.  
  1225.     getpname(fname);
  1226.     if (ctlc_hit == TRUE)
  1227.     {
  1228.         ctlc_hit = FALSE;
  1229.         return;
  1230.     }
  1231.     if (strblank(fname))
  1232.         return;
  1233.     strbtrim(fname);
  1234.  
  1235. /*
  1236. ** the file has been opened successfully...now switch the
  1237. ** comport mode to 8 bits for xmodem protocol
  1238. */
  1239.     if (comm_setup(port,pbaud,NPARITY,BIT8,pstop) == ERR)
  1240.     {
  1241.         wperror("Unable to switch line mode");
  1242.         return;
  1243.     }
  1244. /*
  1245. ** process the download
  1246. */
  1247.     if (protocol == YMODEM)
  1248.         lcym_recv(p, fname);
  1249.     else
  1250.         lczm_recv(p, pbaud, fname);
  1251.  
  1252.     comm_setup(port,pbaud,pparity,pbits,pstop);
  1253. }
  1254.  
  1255. int kb_abort(void)
  1256. {
  1257.     char ch;
  1258.  
  1259.     if (kbmhit())
  1260.     {
  1261.         ch = getxch();
  1262.         if (ch == 0x1b)                    /* escape ? */
  1263.             return(TRUE);
  1264.     }
  1265.     return (FALSE);
  1266. }
  1267.